﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminPage.master" Inherits="WebManager.BasePage" %>

<%@ Import Namespace="TalentPools.BLL" %>
<%@ Import Namespace="TalentPools.Model" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<script runat="server">
    string session;
    AdminClass a = new AdminClass();
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        ViewState["where"] = MyFormatstr(searchText.Text.Trim());
    }

    protected void AspNetPager1_PageChanging(object src, PageChangingEventArgs e)
    {
        ViewState["PageIndex"] = e.NewPageIndex;
    }
    public void DataBind1()
    {
        RP1.DataSource = new Company_LoginManager().GetLoginPage(Convert.ToInt32(ViewState["PageIndex"]), 10, ViewState["where"].ToString());
        RP1.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!AdminLogin())
        {
            Response.Redirect("Admin_Login.aspx");
            return;
        }
        session = Request.Cookies["AdminUser"].Values["name"];
        if (!a.Exists_Purview(session, "2101"))
        {
            JsWindows("对不起，你没有权限进行此操作！", "Admin_Default.aspx");
            return;
        }
        if (!IsPostBack)
        {
            ViewState["PageIndex"] = 1;//默认第一页
            ViewState["where"] = "";//默认全部
            string qstr = QueryString("Action");
            switch (qstr)
            {
                case "Edit":
                    if (!a.Exists_Purview(session, "2101"))
                    {
                        JsWindows("对不起，你没有该权限", "Company_LoginManager.aspx");
                        return;
                    }
                    EditVoid();
                    break;
                case "Del":
                    if (!a.Exists_Purview(session, "2103"))
                    {
                        JsWindows("对不起，你没有该权限", "Company_LoginManager.aspx");
                        return;
                    }
                    break;
                case "Set":
                    if (!a.Exists_Purview(session, "2101"))
                    {
                        JsWindows("对不起，你没有该权限", "Company_LoginManager.aspx");
                        return;
                    }
                    SetVoid();
                    break;
                case "Past":
                    if (!a.Exists_Purview(session, "2101"))
                    {
                        JsWindows("对不起，你没有该权限", "Company_LoginManager.aspx");
                        return;
                    }
                    PastVoid();
                    break;
            }
            AspNetPager1.RecordCount = new Company_LoginManager().GetLoginCount(ViewState["where"].ToString());
            DataBind1();
        }
    }
    public void EditVoid()
    {
        bool result = false;
        int id = Convert.ToInt32(QueryString("id"));
        string state = QueryString("state");
        if (state != "True")
        {
            result = true;
        }
        new Company_LoginManager().UpdateTj(id, result);
    }
    public void DelVoid()
    {
        JsWindows("抱歉，此功能尚未开放", "");
        return;
    }
    public void SetVoid()
    {
        bool result = false;
        int id = Convert.ToInt32(QueryString("id"));
        string state = QueryString("state");
        if (state != "True")
        {
            result = true;
        }
        new Company_LoginManager().UpdateState(id, result);
    }
    public void PastVoid()
    {
        bool result = false;
        int id = Convert.ToInt32(QueryString("id"));
        string state = QueryString("state");
        if (state != "True")
        {
            result = true;
        }
        new Company_LoginManager().UpdatePast(id, result);
    }
    public string vipshow()
    {
        string str = Eval("IsVip").ToString();
        if (str == "True")
        {
            return "<span style='color:red'>！Vip</span>";
        }
        else
        {
            return "普通";
        }
    }
    public string tjshow()
    {
        string str = Eval("Istj").ToString();
        if (str == "True")
        {
            return "<span style='color:red'>！推荐</span>";
        }
        else
        {
            return "普通";
        }
    }
    public string pastshow()
    {
        string str = Eval("IsPast").ToString();
        if (str == "True")
        {
            return "<span style='color:red'>审核</span>";
        }
        return "未审核";
    }

    protected void sh_button_Click(object sender, EventArgs e)
    {
        string select_Val = Request["ic"];
        if (select_Val == null)
        {
            return;
        }
        string[] id = select_Val.Split(',');
        foreach (string item in id)
        {
            new Company_LoginManager().UpdatePast(Convert.ToInt32(item), true);
        }
        DataBind1();
    }

    protected void nsh_button_Click(object sender, EventArgs e)
    {
        string select_Val = Request["ic"];
        if (select_Val == null)
        {
            return;
        }
        string[] id = select_Val.Split(',');
        foreach (string item in id)
        {
            new Company_LoginManager().UpdatePast(Convert.ToInt32(item), false);
        }
        DataBind1();
    }

    protected void vip_button_Click(object sender, EventArgs e)
    {
        string select_Val = Request["ic"];
        if (select_Val == null)
        {
            return;
        }
        string[] id = select_Val.Split(',');
        foreach (string item in id)
        {
            new Company_LoginManager().UpdateState(Convert.ToInt32(item), true);
        }
        DataBind1();
    }

    protected void QXvip_button_Click(object sender, EventArgs e)
    {
        string select_Val = Request["ic"];
        if (select_Val == null)
        {
            return;
        }
        string[] id = select_Val.Split(',');
        foreach (string item in id)
        {
            new Company_LoginManager().UpdateState(Convert.ToInt32(item), false);
        }
        DataBind1();
    }

    protected void btnDel_Click(object sender, EventArgs e)
    {
        string select_Val = Request["ic"];
        if (select_Val == null)
        {
            return;
        }
        string[] id = select_Val.Split(',');
        foreach (string item in id)
        {
            new Company_LoginManager().DeleteLogin(Convert.ToInt32(item));
        }
        DataBind1();
    }

    protected void tj_button_Click(object sender, EventArgs e)
    {
        string select_Val = Request["ic"];
        if (select_Val == null)
        {
            return;
        }
        string[] id = select_Val.Split(',');
        foreach (string item in id)
        {
            new Company_LoginManager().UpdateTj(Convert.ToInt32(item), true);
        }
        DataBind1();
    }

    protected void qxtj_button_Click(object sender, EventArgs e)
    {
        string select_Val = Request["ic"];
        if (select_Val == null)
        {
            return;
        }
        string[] id = select_Val.Split(',');
        foreach (string item in id)
        {
            new Company_LoginManager().UpdateTj(Convert.ToInt32(item), false);
        }
        DataBind1();
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript">
        function checkAll() {
            var oInput = document.getElementsByName("ic");
            for (var i = 0; i < oInput.length; i++) {
                if (document.getElementById("all").checked == true) {
                    oInput[i].checked = true;
                }
                else {
                    oInput[i].checked = false;
                }
            }
        }

        function checkSingle() {
            var oInput = document.getElementsByName("ic");
            var j = 0;
            for (var i = 0; i < oInput.length; i++) {
                if (oInput[i].checked == true) {
                    j = j + 1;
                }
            }

            if (j == oInput.length) {
                document.getElementById("all").checked = true;
            }
            else {
                document.getElementById("all").checked = false;
            }
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:Panel ID="ManageP" runat="server">
        <table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>
            <tr class='topbg2'>
                <td width="100%" align='center'>
                    <strong class="Glow">企 业 用 户 管 理</strong>
                </td>
            </tr>
        </table>
        <table border="0" width="100%">
            <tr>
                <td>
                    搜索登陆名：
                    <asp:TextBox ID="searchText" runat="server"></asp:TextBox>
                    <asp:Button ID="btn_search" runat="server" Text="搜 索" OnClick="btnSearch_Click" />
                </td>
            </tr>
        </table>
        <table width='100%' border='0' align='center' cellpadding='4' cellspacing='1' class='border'>
            <tr class='topbg2'>
                <td width="6%" align='center'>
                    <strong class="Glow">选中</strong>
                </td>
                <td width="12%" align='center'>
                    <strong class="Glow">登录名</strong>
                </td>
                <td width="14%" align='center'>
                    <strong class="Glow">注册IP</strong>
                </td>
                <td width="11%" align='center'>
                    <strong class="Glow">注册问题</strong>
                </td>
                <td width="10%" align='center'>
                    <strong class="Glow">注册答案</strong>
                </td>
                <td width="14%" align='center'>
                    <strong class="Glow">注册时间</strong>
                </td>
                <td width="10%" align='center'>
                    <strong class="Glow">电子邮箱</strong>
                </td>
                <td width="23%" align='center'>
                    <strong class="Glow">VIP/推荐/审核/操作</strong>
                </td>
            </tr>
            <asp:Repeater ID="RP1" runat="server">
                <ItemTemplate>
                    <tr class='tdbg' onmouseout="this.className='tdbg'" onmouseover="this.className='tdbgmouseover'">
                        <td width="6%" align='center'>
                            <input name="ic" type="checkbox" size="12px" onclick="checkSingle()" style="width: 20px"
                                value='<%#Eval("Id") %>' />
                        </td>
                        <td width="12%" align='center'>
                            <%#Eval("CompanyName")%>
                        </td>
                        <td width="14%" align='center'>
                            <%#Eval("IPAdd") %>
                        </td>
                        <td width="11%" align='center'>
                            <%#Eval("Question") %>
                        </td>
                        <td width="10%" align='center'>
                            <%#Eval("Answer") %>
                        </td>
                        <td width="14%" align='center'>
                            <%#Eval("RegTime") %>
                        </td>
                        <td width="10%" align='center'>
                            <%#Eval("Email") %>
                        </td>
                        <td align="center">
                            <a href="?Action=Set&id=<%#Eval("Id") %>&state=<%#Eval("IsVip") %>">
                                <%#vipshow() %></a> | <a href="?Action=Edit&id=<%#Eval("Id")%>&state=<%#Eval("Istj") %>">
                                    <%#tjshow() %></a> | <a href="?Action=Past&id=<%#Eval("Id") %>&state=<%#Eval("IsPast") %>">
                                        <%#pastshow() %></a> | <a href="?id=<%#Eval("Id") %>&Action=Del" onclick="return confirm('警告！删除此会员将会删除其所有其他相关资料！此操作不可逆。');">
                                            删除</a>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table>
        <div>
            <input name='all' type='checkbox' onclick='checkAll()' value='checkbox' />
            <asp:Button ID="del_button" runat="server" Text="删 除" OnClick="btnDel_Click" />
            <asp:Button ID="sh_button" runat="server" Text="审 核" OnClick="sh_button_Click" />
            <asp:Button ID="nsh_button" runat="server" Text="未审核" OnClick="nsh_button_Click" />
            <asp:Button ID="vip_button" runat="server" Text="VIP" OnClick="vip_button_Click" />
            <asp:Button ID="QXvip_button" runat="server" Text="取消VIP" OnClick="QXvip_button_Click" />
            <asp:Button ID="tj_button" runat="server" Text="推 荐" OnClick="tj_button_Click" />
            <asp:Button ID="qxtj_button" runat="server" Text="取消推荐" OnClick="qxtj_button_Click" />
            <div style="float: right; width: 60%; height: 28px; text-align: right">
                <webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanging="AspNetPager1_PageChanging">
                </webdiyer:AspNetPager>
            </div>
        </div>
        <div id="paging" runat="server">
        </div>
    </asp:Panel>
</asp:Content>
